--[[
	去各个游戏获得金豆桌的列表，入参游戏名， psz， mjzz， dn
]]
local filename = "getcoinpubtablelist.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"

local json = require "cjson"
json.encode_sparse_array(true,1,1)


local service = nil
local CMD = {
	service = nil
}

--获取金豆匹配场列表
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end

    local realnode = ""
    local gamename = msgbody.gamename
    if service.gamenode_config_ab[gamename] then
        realnode = gamename .. "nod" .. service.gamenode_config_ab[gamename]
    else
        realnode = gamename .. "node"
    end
	local list = {mylist = {}, publist = {}, matchlist = {}}
	local is_ok,tablelist = pcall(cluster.call,realnode, ".router", "getcoinmatchlist", rid)
    if is_ok and tablelist then
        list.mylist = tablelist.mylist or {}
        list.publist = tablelist.publist or {}
        list.matchlist = tablelist.matchlist or {}
	    for k,v in pairs(tablelist.mylist) do
		    list.mylist[k]["conf_intro"] = json.encode(tablelist.mylist[k]["conf_intro"])
	    end
	    for k,v in pairs(tablelist.publist) do
		    list.publist[k]["conf_intro"] = json.encode(tablelist.publist[k]["conf_intro"])
	    end
        for k,v in pairs(tablelist.matchlist) do
		    list.matchlist[k]["conf_intro"] = json.encode(tablelist.matchlist[k]["conf_intro"])
	    end
    end
    
	return {gamename=gamename, publist= list.publist, mylist = list.mylist,matchlist = list.matchlist}
    -- return {retcode = -1, retstr = "获取房间列表失败" }
end

return CMD
